package com.cloud.phone.base

import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.provider.Settings
import androidx.appcompat.app.AppCompatActivity
import com.cloud.phone.MainActivity
import com.cloud.phone.constants.Constants

/**
 * @auth: njb
 * @date: 2024/6/11 15:37
 * @desc: 描述
 */
open class BaseActivity : AppCompatActivity() {
    private val TAG = "BaseActivity"
    companion object{
        val mInstance by lazy(LazyThreadSafetyMode.SYNCHRONIZED) {
            BaseActivity()
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        BaseApp.app.addActivity(this)
    }

    fun requestOverlayPermission() {
        if (!Settings.canDrawOverlays(this)) {
            val ACTION_MANAGE_OVERLAY_PERMISSION =
                "android.settings.action.MANAGE_OVERLAY_PERMISSION"
            val intent =
                Intent(
                    ACTION_MANAGE_OVERLAY_PERMISSION,
                    Uri.parse("package:$packageName")
                )
            startActivityForResult(intent, Constants.REQUEST_OVERLAY)
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        BaseApp.app.removeActivity(this)
    }
}